﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MVCms.Core.Entities;

namespace MVCms.Core.Services
{
    public static class SimpleDataService
    {
        /// <summary>
        /// Saves the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        public static void Save(this SimpleData data)
        {
            DataAccess.McContext.Save(data);
        }

        /// <summary>
        /// Gets the specified data.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        public static SimpleData Get(VirtualPage page, string key)
        {
            return
                DataAccess.McContext.Load<SimpleData>().Where(w => w.DataKey == key && w.Page == page)
                    .FirstOrDefault();
        }

        /// <summary>
        /// Gets the specified data (!! NOT YET IMPLEMENTED !!).
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="module">The module.</param>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        public static SimpleData Get(VirtualPage page, PageModule module, string key)
        {
            return
                DataAccess.McContext.Load<SimpleData>().Where(w => w.DataKey == key && w.Page == page && w.Module == module)
                    .FirstOrDefault();
        }
    }
}
